﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LightManager.UserControls
{
    public partial class LifeStatusControl : UserControl
    {
        public LifeStatusControl()
        {
            InitializeComponent();
            List<WoundType> dummy = new List<WoundType>();
            for (int i = 0; i < 20; i++)
                dummy.Add(WoundType.Wounded);
            this.SetHearts(dummy);
        }

        public Unit DataSource
        {
            set
            {
                this.SetHearts(value.LifeStatus);
            }
        }

        private void SetHearts(List<WoundType> lifes)
        {
            this.flowLayoutPanel.SuspendLayout();
            this.flowLayoutPanel.Controls.Clear();
            int i = 0;
            int b = 0;
            foreach (WoundType life in lifes)
            {
                i++; b++;
                PictureBox picbox = new PictureBox();
                picbox.SizeMode = PictureBoxSizeMode.AutoSize;
                picbox.Image = this.imageList.Images[life.ToString()];
                picbox.Margin = (i != 5) ? new Padding(1, 4, 1, 1) : new Padding(1, 4, 4, 1);
                if (i == 5) i = 0;
                this.flowLayoutPanel.Controls.Add(picbox);
                if (b >= 10)
                {
                    this.flowLayoutPanel.SetFlowBreak(picbox, true);
                    b = 0;
                }
            }
            this.flowLayoutPanel.ResumeLayout();
        }
    }
}
